package cn.example.zjgsu.controller;

import cn.example.zjgsu.pojo.result.JsonData;
import cn.example.zjgsu.service.LoadPageServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: miaopeihan
 * @date: 2020-03-18  16:42
 */

@RestController
@RequestMapping({"/v1/api/loadpage"})
@Api(description = "用户登陆")
@CrossOrigin
public class LoadPageController {

    @Autowired
    LoadPageServer loadPageServer;

    @ApiOperation("判断是否存在用户")
    @PostMapping(value = "/isAccountExist")
    public JsonData isAccountExist(@RequestParam String account, @RequestParam String password) {
        boolean state=loadPageServer.isAccountExist(account,password);
        return JsonData.success(state);
    }

    @ApiOperation("注册用户")
    @PostMapping(value = "/registerUser")
    public JsonData registerUser(@RequestParam String account, @RequestParam String name,@RequestParam String password,@RequestParam String city) {
        boolean state=loadPageServer.isRegisterSuccess(account,name,password,city);
        return JsonData.success(state);
    }

    @ApiOperation("修改密码")
    @PostMapping(value = "/modifyPassword")
    public JsonData modifyPassword(@RequestParam String account, @RequestParam String oldPassword,@RequestParam String newPassword) {
        boolean state=loadPageServer.isModifyPasswordSuccess(account,oldPassword,newPassword);
        return JsonData.success(state);
    }

}
